﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SubSonic;

namespace AppBox.admin
{
    public partial class user_view : PageBase
    {
        private static readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        #region Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            btnClose.OnClientClick = ExtAspNet.ActiveWindow.GetHideReference();

            int id = GetQueryIntValue("id");
            XUser current = XUser.FetchByID(id);
            if (current == null)
            {
                // 参数错误，首先弹出Alert对话框然后关闭弹出窗口
                ExtAspNet.Alert.Show("参数错误！", String.Empty, ExtAspNet.ActiveWindow.GetHideReference());
                return;
            }


            labName.Text = current.Name;
            labRealName.Text = current.RealName;
            labEmail.Text = current.Email;
            labCellPhone.Text = current.CellPhone;
            labOfficePhone.Text = current.OfficePhone;
            labHomePhone.Text = current.HomePhone;
            labRemark.Text = current.Remark;
            labEnabled.Text = current.Enabled ? "启用" : "禁用";
            labGender.Text = current.Gender;

            if (current.RoleId != null && current.RoleId != -1)
            {
                XRole role = new Select().From<XRole>()
                    .Where(XRole.IdColumn).IsEqualTo(current.RoleId)
                    .ExecuteSingle<XRole>();

                labRole.Text = role.Name;
            }

            if (current.DeptId != null && current.DeptId != -1)
            {
                XDept dept = new Select().From<XDept>()
                    .Where(XDept.IdColumn).IsEqualTo(current.DeptId)
                    .ExecuteSingle<XDept>();

                labDept.Text = dept.Name;
            }
        }

        #endregion

    }
}
